package com.yjq0713.test1_4;

import java.util.Arrays;

/*习题三
        编写一段程序，实现int score[] = {67, 69, 75, 87, 89, 90, 99, 100}; 由大到小的排序*/
public class Third {
    public static void main(String[] args) {
        int[] score = {67, 69, 75, 87, 89, 90, 99, 100};
        /*冒泡排序法*/
/*        for (int i = 0; i < score.length-1; i++){
            for (int j = i+1; j <= score.length-1; j++){
                if (score[i]<score[j]){
                    int temp = score[i];
                    score[i] = score[j];
                    score[j] = temp;
                }
            }
        }*/
        System.out.println(Arrays.toString(score));
        sq(0, score.length - 1, score);
        System.out.println(Arrays.toString(score));
    }

    /*快速排序法*/
    public static void sq(int left, int right, int[] array) {
        if (left > right) {
            return;
        }
        int a = left, b = right;
        int len = array[left];
        while (a != b) {
            while (len >= array[b] && a < b) {
                b--;
            }
            while (len <= array[a] && a < b) {
                a++;
            }
            if (a < b) {
                int temp = array[a];
                array[a] = array[b];
                array[b] = temp;
            }
        }
        array[left] = array[a];
        array[a] = len;

        sq(left, a - 1, array);
        sq(a + 1, right, array);
    }
}
